package threadDemo;

/**
 * @author Ajie
 * @date 2023/5/4
 * @function
 */
public class Thread_Yield_Demo2 {
    public static void main(String[] args) {
        Runnable task1 = () -> {
            for (int i = 1; i <= 5; i++) {
                System.out.println("Task 1, step " + i +" yield---");
                Thread.yield();
                System.out.println("Task 1, step " + i +" yield---over");
            }
        };

        Runnable task2 = () -> {
            for (int i = 1; i <= 5; i++) {
                System.out.println("Task 2, step " + i +" yield************");
                Thread.yield();
                System.out.println("Task 2, step " + i +" yield************over");
            }
        };

        Thread thread1 = new Thread(task1);
        Thread thread2 = new Thread(task2);

        thread1.start();
        thread2.start();
    }
}
